package Person.jihe;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class HashMapDemo {
    public static void main(String[] args) {
        //创建HashMap  集合对象
        HashMap<String,Student> hm = new HashMap<String,Student>();
    //创建学生对象
        Student s1 = new Student("户总",19);
Student s2= new Student("黄总",20);
Student s3 = new Student("龙总",30);
//把学生添加到集合中
        hm.put("ith001",s1);
        hm.put("ith002",s2);
        hm.put("ith003",s3);
//方法一： 键找值
Set<String> keySet = hm.keySet();
for(String key:keySet){
    Student value = hm.get(key);
    System.out.println(key+","+value.getName()+","+value.getAge());

}
        System.out.println("------------");
//方法2：
Set<Map.Entry<String,Student>> entrySet = hm.entrySet();
for(Map.Entry<String,Student> me:entrySet){
    String key = me.getKey();
    Student value = me.getValue();
    System.out.println(key+","+value.getName()+","+value.getAge());;
}


    }
}
